package examples;
import java.util.*;
import search.*;
/**
 * Write a description of class Test here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Test
{
    CityMap map;
    
    public Test()
    {
        map = makeMap();
    }
    
    private CityMap makeMap()
    {
        CityMap map = new CityMap();
        City london = new City("London");
        City brighton = new City("Brighton");
        City hove = new City("Hove");
        City worthing = new City("Worthing");
        City birmingham = new City("Birmingham");
        Road m1 = new Road(london,birmingham, 150);
        Road a23 = new Road(london, brighton, 55);
        Road a27 = new Road(brighton,hove,6);
        Road another = new Road(hove, worthing, 15);
        Road yetAnother = new Road(worthing,london,60);
        map.addEdge(another);
        map.addEdge(yetAnother);
        map.addEdge(a23);
        map.addEdge(a27);
        map.addEdge(m1);
        return map;
    }
    
    public void findRoute(String start, String end)
    {
        FindRouteVisitor visitor = new FindRouteVisitor(map,start,end);
        SearchNode<City> x = map.accept(visitor);
        
        printRoute(x);
        System.out.println("Cost is " + x.getCost());
        System.out.println("Depth is " + x.getDepth());
    }
    
    public void printRoute(SearchNode<City> x)
    {
        if (x == null) {
            return;
        }
        else {
            printRoute(x.getParent());
            System.out.println(x.getState().getData());
        }
    }
    
}
